package com.jhd.fuzhou.view.task;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.jhd.fuzhou.view.login.BaseActivity;
import com.jhd.fuzhou.R;
import com.jhd.fuzhou.adapter.TaskDocumentAdapter;
import com.jhd.fuzhou.util.CustomToast;
import com.jhd.fuzhou.vo.SuperviseEnclosureVo;
import com.jhd.fuzhou.vo.SupervisionInspectionVo;

import java.io.File;
import java.util.List;

import butterknife.BindView;

import static java.lang.Thread.sleep;

public class DocumentActivity extends BaseActivity {

    private SupervisionInspectionVo supervisionInspectionVo;
    @BindView(R.id.recyclerView)RecyclerView recyclerView;
    /*@BindView(R.id.rv_asking_record)RecyclerView rv_asking_record;
    @BindView(R.id.rv_scene_record)RecyclerView rv_scene_record;
    @BindView(R.id.rv_supervision_opinions)RecyclerView rv_supervision_opinions;
    @BindView(R.id.lin_asking_record)LinearLayout lin_asking_record;
    @BindView(R.id.lin_scene_record)LinearLayout lin_scene_record;
    @BindView(R.id.lin_supervision_opinions)LinearLayout lin_supervision_opinions;*/
    private Context context=this;
    private List<SuperviseEnclosureVo> superviseEnclosureVoList;
    private List<File> files;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_document);
    }

    @Override
    protected void processLogic() {
        onBack();
        String data=getIntent().getStringExtra("data");
        supervisionInspectionVo= JSON.parseObject(data, SupervisionInspectionVo.class);
        if("0".equals(supervisionInspectionVo.getSupervisedType())){
            superviseEnclosureVoList=supervisionInspectionVo.getSuperviseEnclosureVoList();
        }else {
            superviseEnclosureVoList=supervisionInspectionVo.getDocumentAttachmentList();
        }
        if(superviseEnclosureVoList!=null&&superviseEnclosureVoList.size()>0){
            /*files=new ArrayList<>();
            for(int i=0;i<superviseEnclosureVoList.size();i++){
                int finalI = i;
                new Thread(){
                        @Override
                        public void run() {
                            try{
                                files.add(download(superviseEnclosureVoList.get(finalI).getEnclosureUrl()));
                            }catch (Exception e){

                            }
                        }
                    }.start();
            }*/
            LinearLayoutManager linearLayoutManager=new LinearLayoutManager(context);
            recyclerView.setLayoutManager(linearLayoutManager);
            TaskDocumentAdapter adapter=new TaskDocumentAdapter(superviseEnclosureVoList,context);
            recyclerView.setAdapter(adapter);
            /*for (SuperviseEnclosureVo superviseEnclosureVo : superviseEnclosureVoList) {
                if("询问笔录".equals(superviseEnclosureVo.getEnclosureName())){
                    lin_asking_record.setVisibility(View.VISIBLE);
                    new Thread(){
                        @Override
                        public void run() {
                            super.run();
                            getPDF(superviseEnclosureVo.getEnclosureUrl(),rv_asking_record,"询问笔录.pdf");
                        }
                    }.start();
                }else if("现场笔录".equals(superviseEnclosureVo.getEnclosureName())){
                    lin_scene_record.setVisibility(View.VISIBLE);
                    new Thread(){
                        @Override
                        public void run() {
                            super.run();
                            getPDF(superviseEnclosureVo.getEnclosureUrl(),rv_scene_record,"现场笔录.pdf");
                        }
                    }.start();
                }else if("监督意见书".equals(superviseEnclosureVo.getEnclosureName())){
                    lin_supervision_opinions.setVisibility(View.VISIBLE);
                    new Thread(){
                        @Override
                        public void run() {
                            super.run();
                            getPDF(superviseEnclosureVo.getEnclosureUrl(),rv_supervision_opinions,"监督意见书.pdf");
                        }
                    }.start();
                }
            }*/
        }else{
            CustomToast.showText(context,"没有上传相关文书!",3000,0,0).show();
        }
    }
}